package muilty_thread.pic_java_design_pattern.balking;

import lombok.SneakyThrows;

import java.util.Random;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/10/12 23:38
 */


public class ChangerThread implements Runnable {
    private final Data data;
    private final Random random = new Random();

    public ChangerThread(Data data) {
        this.data = data;
    }

    @SneakyThrows
    @Override
    public void run() {

        for (int i = 0; ; i++) {
            data.change("no." + i);
            Thread.sleep(random.nextInt(1000));
            data.save();
        }
    }
}
